t get this message : 'Move this array "sort" operation to a separate statement'
if (isDefined(this.#Type.externalControls)){
this.#Type.externalControls = this.#Type.externalControls.sort(sortFn);
this.#Type.externalControls.forEach((control: ITypeControl) => {
externalForm.push(new FormControl(control));
});
}
please help me to resolve the issue.
What .sort does is, it sorts the array it's called on in place, and then returns that array. Assigning the return value of .sort to a new variable could well cause confusion, because now you (may) have two references to the same exact (now sorted) array, rather than a reference to a sorted array and a reference to an unsorted array.
That is
const arr = getArr();
const sortedArr = arr.sort();
is confusing, because arr === sortedArr.
The warning is telling you to not use the return value of .sort, to avoid confusing yourself. Change
this.#Type.externalControls = this.#Type.externalControls.sort(sortFn);
to
this.#Type.externalControls.sort(sortFn);